#ifndef __WIZ_BNF_PARSER_STRING_HPP__SHANHAOBO_19800429__
#define __WIZ_BNF_PARSER_STRING_HPP__SHANHAOBO_19800429__

#include "./WizBNFParser.hpp"

namespace Wiz
{
    namespace BNF
    {
        namespace Parser
        {
            namespace String
            {
                template<typename ResultT, typename IteratorT, typename ScannerT>
                WIZ_INLINE ResultT DoParse
                (
                    ScannerT& Scan,
                    IteratorT Frst,
                    IteratorT Lst
                )
                {
                    typedef typename ScannerT::tIterator                         tIterator;
                    tIterator StartItr = Scan.m_Curr;
                    ::Wiz::Size::Type Sz = Lst - Frst;

                    WIZ_ASSERT(Sz > 0);

                    /// ScannerT Implemented AtEnd, operator*, operator++
                    while (Frst < Lst)
                    {
                        if (Scan.AtEnd() || (*Frst != *Scan))
                            return Scan.NoMatch();
                        ++Frst;
                        ++Scan;
                    }

                    return Scan.CreateMatch(Sz, ::Wiz::Null::Type(), StartItr, Scan.m_Curr);
                }

                template <class IteratorT = ::Wiz:Char::Type const*>
                struct Type : public ::Wiz::BNF::Parser::Type<Type<IteratorT>>
                {
                    typedef Type<IteratorT> tThis;

                    Type(IteratorT Frst, IteratorT Lst) : m_First(Frst), m_Last(Lst)
                    {}
                    Type(IteratorT Frst) : m_First(Frst), m_Last(::Wiz::CStr::GetLast(Frst))
                    {}

                    template <class ScannerT>
                    typename ::Wiz::BNF::Parser::Result<tThis, ScannerT>::tType
                    ParseImpl(ScannerT const& Scan) const
                    {
                        typedef ::Wiz::BNF::Parser::Result<tThis, ScannerT>::tType   tResult;
                        typedef typename ScannerT::tValue                            tValue;
                        typedef typename ScannerT::tIterator                         tIterator;

                        return ::Wiz::BNF::Parser::String::DoParse<tResult>(Scan, m_First, m_Last);
                    }
                private:
                    IteratorT m_First;
                    IteratorT m_Last;
                }; /// end of struct Type
            } /// end of namespace String
        } /// end of namespace Parser
    } /// end of namespace BNF
} /// end of namespace Wiz

#endif /*__WIZ_BNF_PARSER_STRING_HPP__SHANHAOBO_19800429__*/
